package com.docker.chy.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.docker.common.annotation.Log;
import com.docker.common.core.controller.BaseController;
import com.docker.common.core.domain.AjaxResult;
import com.docker.common.enums.BusinessType;
import com.docker.chy.domain.DoctorFamily;
import com.docker.chy.service.IDoctorFamilyService;
import com.docker.common.utils.poi.ExcelUtil;
import com.docker.common.core.page.TableDataInfo;

/**
 * 患者家庭关系Controller
 * 
 * @author ruoyi
 * @date 2025-04-09
 */
@RestController
@RequestMapping("/chy/family")
public class DoctorFamilyController extends BaseController
{
    @Autowired
    private IDoctorFamilyService doctorFamilyService;

    /**
     * 查询患者家庭关系列表
     */
    @PreAuthorize("@ss.hasPermi('chy:family:list')")
    @GetMapping("/list")
    public TableDataInfo list(DoctorFamily doctorFamily)
    {
        startPage();
        List<DoctorFamily> list = doctorFamilyService.selectDoctorFamilyList(doctorFamily);
        return getDataTable(list);
    }

    /**
     * 导出患者家庭关系列表
     */
    @PreAuthorize("@ss.hasPermi('chy:family:export')")
    @Log(title = "患者家庭关系", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, DoctorFamily doctorFamily)
    {
        List<DoctorFamily> list = doctorFamilyService.selectDoctorFamilyList(doctorFamily);
        ExcelUtil<DoctorFamily> util = new ExcelUtil<DoctorFamily>(DoctorFamily.class);
        util.exportExcel(response, list, "患者家庭关系数据");
    }

    /**
     * 获取患者家庭关系详细信息
     */
    @PreAuthorize("@ss.hasPermi('chy:family:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(doctorFamilyService.selectDoctorFamilyById(id));
    }

    /**
     * 新增患者家庭关系
     */
    @PreAuthorize("@ss.hasPermi('chy:family:add')")
    @Log(title = "患者家庭关系", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody DoctorFamily doctorFamily)
    {
        return toAjax(doctorFamilyService.insertDoctorFamily(doctorFamily));
    }

    /**
     * 修改患者家庭关系
     */
    @PreAuthorize("@ss.hasPermi('chy:family:edit')")
    @Log(title = "患者家庭关系", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody DoctorFamily doctorFamily)
    {
        return toAjax(doctorFamilyService.updateDoctorFamily(doctorFamily));
    }

    /**
     * 删除患者家庭关系
     */
    @PreAuthorize("@ss.hasPermi('chy:family:remove')")
    @Log(title = "患者家庭关系", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(doctorFamilyService.deleteDoctorFamilyByIds(ids));
    }
}
